'use client'; import React, { useEffect, useMemo, useState } from 'react'; import clsx from 'clsx'; import { useLocalization } from '@akinon/next/hooks'; import { useGetCountriesQuery, useGetStoresQuery, useGetRetailStoreCitiesQuery } from '@akinon/next/data/client/address'; import { Select, Accordion, Button, Icon, SkeletonWrapper, Skeleton } from '@theme/components'; import { GoogleMap, LoadScriptNext, Marker } from '@react-google-maps/api'; import { useForm } from 'react-hook-form'; import { Image } from '@akinon/next/components/image'; type SelectOptionType = { label: string; value: string | number; }; export default function Stores() { const { t } = useLocalization(); const [selectedCityPk, setSelectedCityPk] = useState(null); const [center, setCenter] = useState({ lat: 39.1615254, lng: 35.0687716, zoom: 2 }); const { register, watch } = useForm(); const selectedCountry = watch('country'); const selectedCity = watch('city'); const { data: stores } = useGetStoresQuery(); const { data: country, isLoading: countryLoading } = useGetCountriesQuery(); const { data: city, isLoading: cityLoading } = useGetRetailStoreCitiesQuery( selectedCountry, { skip: !selectedCountry } ); const countryOptions = useMemo(() => { if (country) { const options: SelectOptionType[] = [ { label: t('common.stores.select_country'), value: '' } ]; options.push( ...country.results.map((item) => ({ label: item.name, value: item.pk })) ); return options; } return []; }, [country]); // eslint-disable-line react-hooks/exhaustive-deps const cityOptions = useMemo(() => { if (city) { const options: SelectOptionType[] = [ { label: t('common.stores.select_city'), value: '' } ]; options.push( ...city.results.map((item) => ({ label: item.name, value: item.pk })) ); return options; } return []; }, [city]); // eslint-disable-line react-hooks/exhaustive-deps const handleBackButtonClick = () => { setSelectedCityPk(null); setCenter({ lat: 39.1615254, lng: 35.0687716, zoom: 2 }); }; useEffect(() => { if (selectedCity) { setSelectedCityPk(Number(selectedCity)); } }, [selectedCity]); return (